/**
 * Created with IntelliJ IDEA.
 *
 * @author: cxs
 * @date: 2023/6/27
 * @time: 20:10
 * @className：CustomerServiceImpl
 * @description：
 */
package com.bailan.bus.service.impl;

import com.bailan.bus.domain.Customer;
import com.bailan.bus.mapper.CustomerMapper;
import com.bailan.bus.service.ICustomerService;
import com.bailan.bus.vo.CustomerVo;
import com.bailan.common.util.DataGridView;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl implements ICustomerService {
    @Autowired
    CustomerMapper customerMapper;
    /**
     * 翻页查询客户信息
     * @param customerVo
     * @return
     */
    @Override
    public DataGridView queryAllCustomer(CustomerVo customerVo) {
        //配置页的信息,生成了一个代理对象
        Page<Object> page = PageHelper.startPage(customerVo.getPage(), customerVo.getLimit());
       List<Customer> data=customerMapper.queryAllCustomer(customerVo);
        return new DataGridView(page.getTotal(),data);
    }

    /**
     * 添加用户
     * @param customerVo
     */
    @Override
    public void addCustomer(CustomerVo customerVo) {
        this.customerMapper.insertCustomer(customerVo);
    }

    /**
     * 修改已经存在的用户信息
     * @param customerVo
     */
    @Override
    public void updateCustomer(CustomerVo customerVo) {
        this.customerMapper.updateByPrimaryKey(customerVo);
    }

    /**
     * 通过身份证号单个删除已经存在的客户信息
     * @param identity
     */
    @Override
    public void deleteByIdentity(String identity) {
        this.customerMapper.deleteByIdentity(identity);
    }

    /**
     * 批量删除多个客户
     *需要事务管理，所以必须以delete开头
     * @param ids
     */
    @Override
    public void deleteManyCustomer(String[] ids) {
        for (String id: ids) {
            this.customerMapper.deleteByIdentity(id);
        }
    }

    /**
     * 根据身份证号查询用户
     *
     * @param identity
     * @return
     */
    @Override
    public Customer selectCustomerByIdentity(String identity) {
      return this.customerMapper.queryCustomerByIdentity(identity);
    }
}
